#! /bin/sh
# A script for awd loop attack
# Author: i0gan

attack_times=10000
round_wait_time=540
wait_submit_time=1
log_file="logs"
run_time=3m
next_attack_time=0.2

log() {
	t=`date "+%H:%M:%S"`
	m="[$t]$m"
	info="\033[43;37m $m ]\033[0m"
	echo -e "$info"
	echo -e "\n$m" >> $log_file
}

attack() {
	rm flags
	for line in `cat hosts`;do
		timeout --foreground $run_time python ./expa $line &
		sleep $next_attack_time
	done
	echo -e "\x1b[47;30m Waitting $wait_submit_time s to submit flag\x1b[0m"
	sleep $wait_submit_time
	echo -e "\x1b[47;30m Submiting flag\x1b[0m"
	cp flags /home/share/flags_1
	#curl url -d "flag=$flag&token=KexQHEuq3tetqMAVYVH3Gk7nkDGHVmamcQ9JDb7tdDRhY"
	#python3 ./submit_flag
}

for((i=1; i <= $attack_times; i++));
do
	m="-------- round $i --------"
	log $m
	attack
	echo -e "\x1b[47;30m Waitting next round\x1b[0m"
	sleep $round_wait_time
done
